 <template>
  <div>
    <el-card class="box-card">
      <div>
        <el-row :gutter="15"
                type="flex"
                align="middle"
                style="margin-bottom:10px">
          <el-col :span="1.5">
            用户昵称
          </el-col>
          <el-col :span="3">
            <el-input size="small"
                      v-model='queryData.nickName'
                      placeholder="用户昵称"></el-input>
          </el-col>
          <el-col :span="1.5">
            标题
          </el-col>
          <el-col :span="3">
            <el-input size="small"
                      v-model='queryData.title'
                      placeholder="请输入标题"></el-input>
          </el-col>
          <el-col :span="1.5">
            类型
          </el-col>
          <el-col :span="3">

            <el-select v-model="queryData.ty"
                       size="small"
                       placeholder="请选择">
              <el-option label="动态"
                         :value="1">
              </el-option>

              <el-option label="恋爱感悟"
                         :value="2">
              </el-option>
              <el-option label="感悟分享"
                         :value="3">
              </el-option>
            </el-select>
          </el-col>

          <el-col :span="1.5">
            状态
          </el-col>
          <el-col :span="3">

            <el-select v-model="queryData.sh"
                       size="small"
                       placeholder="请选择">
              <el-option label="待审核"
                         :value="1">
              </el-option>
              <el-option label="通过"
                         :value="2">
              </el-option>
              <el-option label="失败"
                         :value="3">
              </el-option>

            </el-select>
          </el-col>
          <el-col :span="1.5">
            <el-button size="mini"
                       type="primary"
                       icon="el-icon-search"
                       @click="getDate()">搜索</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button icon='el-icon-refresh'
                       size="mini"
                       @click="reset()">重置</el-button>
          </el-col>
        </el-row>
      </div>

      <el-table :data="tableData"
                v-loading="loading"
                style="width: 100%"
                :header-cell-style="{background:'#f8f8f9','text-align':'center'}"
                :cell-style="{'text-align':'center'}">
        <el-table-column type="selection"
                         width="120">
        </el-table-column>
        <el-table-column prop="id"
                         label="用户动态id">
        </el-table-column>
        <el-table-column prop="nickName"
                         label="用户昵称">
        </el-table-column>
        <el-table-column prop="title"
                         label="标题">

        </el-table-column>
        <el-table-column prop="content"
                         label="内容">

        </el-table-column>
        <el-table-column prop="address"
                         label="所在位置">
        </el-table-column>
        <el-table-column prop="previewNum"
                         label="预览量">
        </el-table-column>
        <el-table-column prop="ty"
                         label="类型">
          <template slot-scope="scope">
            <span>{{scope.row.ty==1?'动态':scope.row.ty==2?'恋爱感悟':'感悟分享'}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="ty"
                         label="状态">
          <template slot-scope="scope">
            <span>{{scope.row.sh==1?'待审核':scope.row.sh==2?'通过':'失败'}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="dynamicPicList"
                         label="图片">
          <template slot-scope="scope">

            <el-image v-if="scope.row.dynamicPicList[0]"
                      style="width: 60px; height: 60px;"
                      :src="scope.row.dynamicPicList[0].picUrl"
                      :preview-src-list="[scope.row.dynamicPicList[0].picUrl]">
            </el-image>

            <!-- <span>{{scope.row.dynamicPicList[0].picUrl}}</span> -->
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template v-slot="data">
            <el-button icon="el-icon-edit"
                       type="text"
                       @click="updateHandler(data.row.id)">修改</el-button>
            <el-button icon="el-icon-edit"
                       type="text"
                       @click="sele(data.row.id)">查看评论</el-button>
            <el-button icon="el-icon-delete"
                       type="text"
                       @click="deleteHandler(data.row.id)">删除</el-button>
          </template>

        </el-table-column>

      </el-table>
      <div class="page"
           v-show="total!=0">
        <el-pagination background
                       @size-change="handleSizeChange"
                       @current-change="handleCurrentChange"
                       :current-page="queryData.pageNum"
                       :page-sizes="[3, 5, 7, 9]"
                       :page-size="queryData.pageSize"
                       layout="total, sizes, prev, pager, next, jumper"
                       :total="total">
        </el-pagination>
      </div>
    </el-card>

    <div>
      <el-dialog title="修改用户状态"
                 :visible.sync="dialogVisible"
                 width="30%">
        <el-form :model="formData"
                 ref="ruleForm"
                 label-width="80px">

          <el-form-item label="状态"
                        prop="sh">
            <el-select placeholder="请选择"
                       v-model="formData.sh">
              <el-option label="待审核"
                         :value="1">
              </el-option>
              <el-option label="通过"
                         :value="2">
              </el-option>
              <el-option label="失败"
                         :value="3">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="推荐"
                        prop="tj">
            <el-select placeholder="请选择"
                       v-model="formData.tj">
              <el-option label="不推荐"
                         :value="1">
              </el-option>
              <el-option label="推荐"
                         :value="2">
              </el-option>

            </el-select>
          </el-form-item>

        </el-form>
        <span slot="footer"
              class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary"
                     @click="update">确 定</el-button>
        </span>
      </el-dialog>
    </div>

    <div>
      <el-dialog title="查看评论"
                 :visible.sync="dialogVisible2"
                 width="50%">
        <div>
          <el-button size="mini"
                     type="danger"
                     icon="el-icon-delete"
                     plain
                     :disabled='checkItem.length==0'
                     @click="delMore1">删除</el-button>
        </div>
        <el-table :data="plData"
                  v-loading="loading"
                  style="width: 100%"
                  :header-cell-style="{background:'#f8f8f9','text-align':'center'}"
                  :cell-style="{'text-align':'center'}"
                  @selection-change="handleSelectionChange">
          <el-table-column type="selection"
                           width="120">
          </el-table-column>
          <el-table-column prop="nickName"
                           label="用户动态昵称">
          </el-table-column>
          <el-table-column prop="content"
                           label="评论内容">
          </el-table-column>

          <el-table-column label="操作">
            <template v-slot="data">
              <el-button icon="el-icon-delete"
                         type="text"
                         @click="del(data.row.id)">删除</el-button>
            </template>

          </el-table-column>

        </el-table>
      </el-dialog>
    </div>

  </div>
</template>


<script>
import quillEditor from '../../../components/Quill'
export default {
  components: { quillEditor },
  data() {
    return {
      checkItem: [],
      plid: null,
      queryData: {
        pageNum: 1,
        pageSize: 5,
        nickName: null,
        title: null,
        ty: null,
        sh: null
      },
      plData: [],
      loading: false,
      dialogVisible2: false,
      tableData: [],
      total: 0,

      dialogVisible: false,
      formData: {
        address: null,
        content: null,
        contentPic: null,
        createBy: null,
        createTime: null,
        dyType: null,
        dynamicPicList: null,
        dynamicPlList: null,
        dzNum: null,
        id: null,
        isDel: null,
        isDz: null,
        isGz: null,
        isRz: null,
        isSc: null,
        lat: null,
        lng: null,
        nickName: null,
        params: {},
        plNum: null,
        previewNum: null,
        remark: null,
        scNum: null,
        searchValue: null,
        sh: null,
        title: null,
        tj: null,
        txUrl: null,
        ty: null,
        uid: null,
        updateBy: null,
        updateTime: null,
        zfNickName: null,
        zfUid: null
      }
    }
  },
  mounted() {
    this.getDate()
  },
  methods: {
    del(id) {
      this.deletePl(id)
    },
    delMore1() {
      let ids = this.checkItem.map((el) => el.id)
      this.deletePl(ids)
    },
    deletePl(id) {
      this.$confirm(`是否确认删除编号为${id.toString()}的数据项?`, '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          let data = await this.$axios.delete(`dynamic/pl/${id.toString()}`)

          if (data.data.code != 200) this.$message.error(data.data.msg)
          this.$message({
            type: 'success',
            message: data.data.msg
          })
          this.sele(this.plid)
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    async getDate() {
      this.loading = true

      let { data } = await this.$axios.get('dynamic/dynamic/list', { params: this.queryData })
      console.log(data)

      this.tableData = data.rows
      this.total = data.total
      this.loading = false
    },
    handleSizeChange(val) {
      this.queryData.pageSize = val
      this.getDate()
    },
    handleCurrentChange(val) {
      this.queryData.pageNum = val
      this.getDate()
    },
    search() {
      this.getDate()
    },
    reset() {
      this.queryData = {
        pageNum: 1,
        pageSize: 5,
        nickName: null,
        title: null,
        ty: null,
        sh: null
      }
      this.getDate()
    },
    deleteHandler(id) {
      this.$confirm(`是否确认删除id为?${id}的数据项`, '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          let { data } = await this.$axios.delete(`dynamic/dynamic/${id}`)
          if (data.code == 200) {
            console.log(data)
            this.$message({ type: 'success', message: data.msg })
            this.getDate()
          }
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    async updateHandler(id) {
      this.dialogVisible = true

      let { data } = await this.$axios.get(`dynamic/dynamic/${id}`)
      this.formData = data.data
    },

    async update() {
      let { data } = await this.$axios.put('dynamic/dynamic', this.formData)

      if (data.code != 200) return this.$message.error(data.msg)
      this.$message({
        message: data.msg,
        type: 'success'
      })
      this.dialogVisible = false
      this.getDate()
    },

    async sele(id) {
      this.plid = id
      this.dialogVisible2 = true
      let { data } = await this.$axios.get(`dynamic/pl/list?dyId=${id}`)
      console.log(data)
      this.plData = data.data
    },
    delMore() {},
    handleSelectionChange(val) {
      this.checkItem = val
      console.log(this.checkItem)
    }
  }
}
</script>

<style>
.page {
  margin-top: 15px;
  display: flex;
  justify-content: flex-end;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>